from django.http import JsonResponse
from django.shortcuts import render, redirect
import pymysql
from appBack.utils import DB


def del_lol(request):
    print(request.method)
    if request.GET.get("id"):
        try:
            id = request.GET.get("id")
            host = '119.91.139.114'
            user = 'ShiXi'
            password = 'Wey4pPMkyJ2d'
            database = 'django_test'
            connection = pymysql.connect(host=host, user=user, password=password, database=database)
            cursor = connection.cursor()
            query = f"DELETE FROM django_test.LOL WHERE id = {id};"
            print(query)
            cursor.execute(query)
            res = connection.commit()
            print(res)
        except Exception as e:
            print(e)
            return JsonResponse({'res': False}) #{'res': False}
        finally:
            if cursor:
                cursor.close()
        return redirect('/lol_list/') #{'res': True}

    return JsonResponse({'res': False}) #{'res': False}